package com.anti.modular.sys.log.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.api.Result;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.sys.log.param.SysOpLogParam;
import com.anti.modular.sys.log.param.SysVisLogParam;
import com.anti.modular.sys.log.service.SysOpLogService;
import com.anti.modular.sys.log.service.SysVisLogService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;

/**
 * 系统日志控制器
 */
@RestController
public class SysLogController {

    @Resource
    private SysVisLogService sysVisLogService;

    @Resource
    private SysOpLogService sysOpLogService;

    /**
     * 查询访问日志
     */
    @Permission
    @GetMapping("/sysVisLog/page")
    public Result visLogPage(PageParam pageParam, SysVisLogParam visLogParam) {
        return Result.data(sysVisLogService.page(pageParam,visLogParam));
    }

    /**
     * 查询操作日志
     */
    @Permission
    @GetMapping("/sysOpLog/page")
    public Result opLogPage(PageParam pageParam,SysOpLogParam sysOpLogParam) {
        return Result.data(sysOpLogService.page(pageParam,sysOpLogParam));
    }

    /**
     * 清空访问日志
     */
    @Permission
    @PostMapping("/sysVisLog/delete")
    @BusinessLog(title = "访问日志_清空", opType = LogAnnotionOpTypeEnum.CLEAN)
    public Result visLogDelete() {
        sysVisLogService.delete();
        return Result.success("访问日志清空完成");
    }

    /**
     * 清空操作日志
     */
    @Permission
    @PostMapping("/sysOpLog/delete")
    @BusinessLog(title = "操作日志_清空", opType = LogAnnotionOpTypeEnum.CLEAN)
    public Result opLogDelete() {
        sysOpLogService.delete();
        return Result.success("操作日志清空完成");
    }
}
